
#include <BPainter>
#include "ImageLayer.h"

ImageLayer::ImageLayer(BWidget* parent) : BWidget(parent)
{
	//this->setBorder(0);
}
ImageLayer::~ImageLayer()
{

}

void ImageLayer::setImage(BImage* image)
{
	if (_image != image)
	{
		if (_image)
			disconnect(_image);
		_image = image;
		if (_image)
			connect(_image, Signal_Dirty, &ImageLayer::slotImageDirty);
		this->fresh();
	}
	this->setSize(_image->size());
}
BImage* ImageLayer::image() const
{
	return _image;
}

void ImageLayer::slotImageDirty()
{
	this->fresh();
}

void ImageLayer::freshEvent(const BEvent& event)
{

}
void ImageLayer::paintEvent(const BEvent& event)
{
	BPainter painter(this);
	painter.drawImage(0, 0, this->width(), this->height(), _image);
}
